#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=50, dir[4][2]={{-1, 0}, {0, -1}, {1, 0}, {0, 1}}, inf=10000;

int min(int a, int b) {
  return a<b ? a : b;
}

class Tree {
public:
  static const int maxnode=maxn*maxn;
  int n, fa[maxnode+1], son[maxnode+1], bro[maxnode+1], f[maxnode+1][3];

  void addSide(int f, int s) {
    fa[s]=f, bro[s]=son[f];
    son[f]=s;
  }

  void solve(int o) {
    int sum[2]={};
    for (int i=son[o]; i; i=bro[i]) {
      solve(i);
      sum[1] += f[i][1];
      sum[0] += min(f[i][0], min(f[i][1], f[i][2]));
    }
    f[o][0] = sum[1];
    f[o][2] = sum[0]+1;
    f[o][1] = inf;
    for (int i=son[o]; i; i=bro[i]) {
      int t=min(f[i][0], min(f[i][1], f[i][2]));
      f[o][1] = min(f[o][1], sum[0]-t+f[i][2]);
    }
  }
};

static bool vis[maxn+1][maxn+1];
void genTree(int fa, int x, int y, int d, bool map[][maxn+2], Tree &t) {
  vis[x][y] = true;
  int o=++t.n;
  t.addSide(fa, o);
  for (int i=0; i<4; i++) {
    int nx=x+dir[i][0], ny=y+dir[i][1];
    if (map[nx][ny]) {
      if (i==d) {
        genTree(fa, nx, ny, d, map, t);
      } else if (!vis[nx][ny]) {
        genTree(o, nx, ny, i, map, t);
      }
    }
  }
}

int main() {
#ifdef DEBUG
  freopen("src.in", "r", stdin);
  freopen("src.out", "w", stdout);
#endif

  static bool map[maxn+2][maxn+2];
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i=1; i<=n; i++) {
    for (int j=1; j<=m; j++) {
      char c;
      scanf(" %c ", &c);
      map[i][j] = c=='.';
    }
  }

  static Tree tree;
  bool flag=false;
  for (int i=1; i<=n && !flag; i++) {
    for (int j=1; j<=m && !flag; j++) {
      if (map[i][j]) {
        int t=map[i-1][j]+map[i][j-1]+map[i][j+1]+map[i+1][j];
        if (t==0) {
          printf("1\n");
          return 0;
        }
        if (t==1) {
          vis[i][j] = flag = true;
          tree.n = 1;
          for (int k=0; k<4; k++) {
            int x=i+dir[k][0], y=j+dir[k][1];
            if (map[x][y]) {
              genTree(1, x, y, k, map, tree);
              break;
            }
          }
          break;
        }
      }
    }
  }

  tree.solve(1);
  printf("%d", min(tree.f[1][1], tree.f[1][2]));

  fclose(stdin);
  fclose(stdout);
  return 0;
}
